package com.sias.Loli.filter;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;
import java.util.logging.Handler;

public class HandleFrist implements HandlerInterceptor {
    private HashSet<String> greedUrl=new HashSet<>();
    public HandleFrist(){
        greedUrl.add("login.html");
        greedUrl.add("leaderinsertvf.do");
        greedUrl.add("VerificationCode.do");
    }
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String str = request.getRequestURI(); //获得请求路径
        System.out.println(str);
        System.out.println(request.getSession().getAttribute("user")!=null);
        for (String g:
             greedUrl) {

            if (str.endsWith(g)){
                return true;}
        }
        Object user = request.getSession().getAttribute("user");
        if (user !=null){
            return true;
        }
        System.out.println("===");
        response.sendRedirect("/login.html");
        return false;
    }
}
